#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int a[N],b[N];
int n;
int find1()
{
	b[1]=1;
	for(int i=2;i<=n+1;i++)
	{
		b[i]=a[i-1]-b[i-2]-b[i-1];
		if(b[i]<0||b[i]>1)
		return 0;
	}
if(b[n+1]==0)
	return 1;
	else
	return 0;
}
int find2()
{
	b[1]=0;
	for(int i=2;i<=n+1;i++)
	{
		b[i]=a[i-1]-b[i-2]-b[i-1];
		if(b[i]<0||b[i]>1)
		return 0;
	}
	if(b[n+1]==0)
	return 1;
	else
	return 0;
}
int main()
{

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int ret=0;
	ret+=find1();
	ret+=find2();
   cout<<ret<<endl;
	return 0;
}
